<?php
/**
 * Created by PhpStorm.
 * User: geolo
 * Date: 2018/8/22
 * Time: 11:16
 */
namespace app\modules\api\models;


use app\models\Setting;
use app\models\Share;
use app\models\User;
use app\modules\mch\models\Model;
use Curl\Curl;
class CodeForm extends Model
{
    public $appid;
    public $code;
    public $secret;
    public function rules()
    {
        return [
            [['app_id', 'code', 'secret',], 'required'],
        ];
    }
    public  function  code(){

        $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->secret}&js_code={$this->code}&grant_type=authorization_code";
        $curl = new Curl();
        $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
        $curl->get($api);
        $res = $curl->response;
        $res = json_decode($res, true);
        return $res;
    }

}